<#assign className = table.className>   
<#assign classNameLower = className?uncap_first> 
<#assign classNameFirstLower = className?uncap_first>   
<#assign classNameLowerCase = className?lower_case>  
package ${basepackage}.controller;

import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import ${basepackage}.model.${className};
import ${basepackage}.service.${className};

import java.util.List;

@RestController
@RequestMapping("/${classNameFirstLower}")
public class ${className}Controller {

    @Autowired
    private ${className}Service ${classNameFirstLower}Service;

    @RequestMapping
    public PageInfo<${className}> getAll(${className} ${classNameFirstLower}) {
        List<${className}> list = ${classNameFirstLower}Service.getAll(${classNameFirstLower});
        return new PageInfo<${className}>(list);
    }

    @RequestMapping(value = "/add")
    public ${className} add() {
        return new ${className}();
    }

    @RequestMapping(value = "/view/{id}")
    public ${className} view(@PathVariable Integer id) {
        ModelAndView result = new ModelAndView();
        ${className} ${classNameFirstLower} = ${classNameFirstLower}Service.getById(id);
        return ${classNameFirstLower};
    }

    @RequestMapping(value = "/delete/{id}")
    public ModelMap delete(@PathVariable Integer id) {
        ModelMap result = new ModelMap();
        ${classNameFirstLower}Service.deleteById(id);
        result.put("msg", "删除成功!");
        return result;
    }

    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public ModelMap save(${className} ${classNameFirstLower}) {
        ModelMap result = new ModelMap();
        String msg = ${classNameFirstLower}.getId() == null ? "新增成功!" : "更新成功!";
        ${classNameFirstLower}Service.save(city);
        result.put("${classNameFirstLower}", ${classNameFirstLower});
        result.put("msg", msg);
        return result;
    }
}
